import { request } from "@/utils/request";

/**
 *获取不同的文章集合
 * @param type
 * @returns
 */
export const getessayanyway = (type: number) => {
  return request.get(`essay/getessayanyway?type=${type}`);
};

/**
 * 获取制定数量的文章
 * @param start
 * @returns
 */
export const getallessay = (start: number, pass: number) => {
  return request.get(`essay/getallessay?start=${start}&size=3&pass=${pass}`);
};

/**
 * 获取文章
 * @param id 文章id
 * @returns
 */
export const getessaydetail = (id: string) => {
  return request.get(`essay/getessaydetail/${id}`);
};

/**
 * 收藏或者取消收藏文章
 * @param userid 用户id
 * @param essayid 文章id
 * @returns
 */
export const changcollect = (userid: number, essayid: number) => {
  return request.post("essay/changcollect", {
    userid,
    essayid,
  });
};

/**
 * 增加文章浏览量
 * @param essayid 文章id
 * @returns
 */
export const addviews = (essayid: number) => {
  return request.put(`essay/addviews/${essayid}`);
};

/**
 * 搜索文章s
 * @param content : 搜索关键字;
 * @returns
 */
export const searchapi = (content: string) => {
  return request.get(`/essay/search/${content}`);
};

/**
 * 发表文章
 * @param title
 * @param content
 * @param label_id
 * @param user_id
 * @param cover
 * @returns
 */
export const publishapi = (
  title: string,
  content: string,
  label_id: number,
  user_id: number,
  cover: string
) => {
  return request.post("/essay/publish", {
    title,
    content,
    cover,
    user_id,
    label_id,
  });
};

/**
 * 根据用户id获取收藏的文章或者发表的文章
 * @param user_id yonghuid
 * @param type 文章类型
 * @returns
 */
export const getbyuserapi = (user_id: number, type: number) => {
  return request.get(`/essay/getbyuser/${user_id}?type=${type}`);
};

/**
 * 删除制定文章
 * @param id
 * @returns
 */
export const deleteessaybyidapi = (id: number) => {
  return request.delete(`/essay/deleteessaybyid/${id}`);
};

/**
 * //根据字段audit查询未读的文章消息的数量
 * @param userid
 * @returns
 */
export const getnotreadycountapi = (userid: number) => {
  return request.get(`/essay/getnotreadycount/${userid}`);
};

/**
 * //查询当前登录用户的所有消息
 * @param userid
 * @returns
 */
export const getallnoticeapi = (userid: number) => {
  return request.get(`/essay/getallnotice/${userid}`);
};

/**
 * //置所有消息为已读
 * @param userid
 * @returns
 */
export const toreadedapi = (userid: number) => {
  return request.patch(`/essay/toreaded/${userid}`);
};
